-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify definitions #116
base: main
Are you sure you want to change the base?
Verify definitions #116
Conversation
@david-a-wheeler Sorry this is kind of overrules your #103 , but there seemed to be some kind of urgency in introducing these changes now. |
@tirix - no problem! I started writing definitional soundness code because I wanted the functionality, but I always seem to "run out of time" to complete it. Thanks for picking up the effort, I'm delighted to see it. |
@digama0 Could you please confirm that this corresponds to what you were describing? |
861ec39
to
7fdcbab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the improvements!
I only have one question.
I pushed some more modifications, the current error reports are basically all true positives now, and it might help to start working on them in parallel with the checker itself. Summary of issues:
|
src/diag.rs
Outdated
DefCkSyntaxUsedBeforeDefinition(tok, saddr) => (format!("Definition Check: '{label}' used before definition", label = t(tok)).into(), vec![( | ||
AnnotationType::Error, | ||
format!("this expression contains an occurrence of '{label}'", label = t(tok)).into(), | ||
stmt, | ||
stmt.span(), | ||
), ( | ||
AnnotationType::Note, | ||
"syntax declared here".into(), | ||
sset.statement(*saddr), | ||
sset.statement(*saddr).label_span(), | ||
)]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we could point to the definition if there is one.
src/defck.rs
Outdated
let free_dummies = free_dummies | ||
.into_iter() | ||
.map(|atom| { | ||
let sref = self.db.statement_by_label(atom).unwrap(); | ||
sref.math_at(1).slice.into() | ||
}) | ||
.sorted() | ||
.collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the things I don't like about the current Formula
interface is that variables are represented as $f
theorem labels, which makes it difficult to interact with Frame
for e.g. DV condition checking (which uses variable indexes and $v Atom
s for representing variables); you have to go through this kind of rigamarole to turn those $f labels into variable names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tirix There seems to be a bug in the grammar parsing, related to this: the statement parse for df-tru
contains vx
nodes even though vx
is not in scope and has not been defined yet. The actual $f
in the context is vx.tru
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerning df-tru
here is how the grammar parsing works:
The grammar
module's FormulaTokenIterator
gets the atom for each token using nameck
's lookup_symbol
:
if let Some(l) = self.nset.lookup_symbol(t.as_bytes()) { ... }
It later uses lookup_float
to get the float if happens to be variable. In none of these calls grammar
can specify a frame context, and nameck
actually only stores the topmost statement for a given token.
Note that the API for definition checking changes in every commit, I wouldn't commit to anything until it's feature-complete. And it has some effects on the Formula API too, since this is the first kind of real theorem-prover-ish thing we are trying to do with metamath-knife inside the main repo. |
When it comes to writing a verifier, I don't like releasing it half baked when only some of the checks required for soundness are implemented. There is a very concrete end point for the implementation. If we want to release something incomplete, then it should err on the side of more false positives, but we already know that this will cause thousands of errors in set.mm so it won't be so helpful. |
Things are almost done now. All the DV checks are implemented, as well as the axiom / def naming checker, which revealed some additional issues that have been pushed to metamath/set.mm#3247 (in particular I put some things as primitive that were actually defined but where the definition was far away from the syntax and other disallowed stuff was in between). There are now three (expected) errors:
which is basically what I've been saying all along. Options now are to add some kind of override, or change the names. |
This deserves a wider discussion. At least Interestingly a
I did not find its trace in MMJ2. Did I miss something? |
Actually this is defined in j_syntax.html:
|
The answer to this is basically given by the same tool that is producing the output above. Being 'linked' to an axiom that does not match the requirements for a definition is not sufficient. In fact, the ax/df check is done early, before we have even done most of the fancy work on definitions:
This was part of an alternative design for the definition justification checker, which would parse the |
I would be a bit disappointed if we get stuck on which of these two to choose and end up not getting the definition verifier merged. Based on my limited understanding, I guess an override is what we have been doing (maybe expressed in words, maybe in the mmj2 definition checker), and a name change is seemingly more intellectually honest in light of things like https://us.metamath.org/mpeuni/bj-ax8.html . Disclaimer: although I have looked at things like https://math.stackexchange.com/questions/231087/what-can-i-do-with-proper-classes and https://en.wikipedia.org/wiki/Zermelo%E2%80%93Fraenkel_set_theory#Virtual_classes I'm not sure I understand this fully. I do gather that I'm not aware of any quick fix other than "some kind of override, or change the names" so we probably are left with those two choices for now regardless of what we do longer term. |
Quick comment, this PR isn't blocked on that issue (alone), I have some local work which continues the main implementation which got pushed off of my "to do immediately" list by something else, but which I plan to return to soon. I did prepare a version which just stubs out the missing part of the checker so that it could be merged, but as expected this leaves about 1300 errors, so it won't be immediately usable. |
Thanks for the clarification. I'm mostly thinking of trying to coordinate:
Not that we have a detailed plan for exactly who does all of this and how but those seem like three of the most wanted enhancements that I've noticed. |
I'd prefer to wait on (2) until most of the in-flight additions have been merged. For (3) I think it can be worked on independently of this issue, they are not really conflicting. |
I'm in favor of merging this first, and handling the remaining questions over If this is merged, we could already implement a metamath-knife based definition checker in set.mm`s CI by just ignoring the 3 exceptions, until they are resolved. |
Just to confirm something I think I know the answer to: is the definition checker complete (assuming that it isn't supposed to handle those three)? That is, does it implement the rules at "Additional rules for definitions" in https://us.metamath.org/mpeuni/conventions.html ?
I mean, this is what we do for mmj2, right? If so, it is hard to see merging this, and adding to CI, as a step backward. |
Since I have had a WIP commit sitting in my local copy for too long, I've pushed it to tirix/metamath-knife@verify_definitions...metamath:metamath-knife:verify_definitions_2 . |
So would @digama0 you like me to create a pull request with those changes, review them, and merge them to this branch? |
This is an in progress version of a pull request adding the definition soundness checks.
All checks are not implemented yet, and errors are not handled (the function panics if anything goes wrong).
The intend is to follow the algorithm provided by @digama0 in #103 to identify definitions.
Based on the identification of definitions, this also adds a function to export the dependencies of definition into a GraphML file format. Redundant dependencies are not checked (for example,
df-ipf
includes two conjunctions, so the edge betweendf-ipf
anddf-an
is doubled).Currently this algorithm fails for these reasons:
ax-hilex
is introduced while there are still several definitions pending (e.g.csh
is defined before, butdf-sh
comes after), which breaks the assumption that definition immediately follow the syntax axioms,ax-riotaBAD
is a redefinition ofcrio
. There should be only one definition for a given definiendum.cmesy
formESyn
does not have a definition